<?php

/*
* File reviews.php for project Rijlesplanner.nl
* Created on 1 dec 2007 at 20:07:05 by Ivar Pruijn
*/
class ads extends modules {

	// Properties:
	protected $name = "ads";
	protected $title = "Advertenties";
	protected $subtitle = "";
	protected $moduleOptions = array ();

	// Methods:

	/**
	* void __construct ()
	* This is the constructor method for this class.
	*/
	public function __construct() {
		parent :: __construct();
		$this->logger = parent :: getLogger();
		$this->user = parent :: getUser();
		$this->template = parent :: getTemplate();
		$this->wsclient = parent :: getWsclient();
	}

	/**
	* Object process()
	*
	* Processes the template and current module
	*
	* @param Smarty template The Smarty template to process (sets variables etc.)
	* @return Smarty The template that has been processed
	*/
	function process(& $template = null) {
		$this->template = $template;
		$this->getRandomAds();
	}

	public function getRandomAds() {
		$this->template->assign('footer_ad',$this->getRandomAd('footer'));
		$this->template->assign('halfbannertop_ad',$this->getRandomAd('halfbannertop'));
	}
	
	public function getRandomAd($position) {
		try {
			
			# Check of we rijschoolId hebben
			if($this->user instanceof Visitor) {
				$rijschoolId = 0;
			} else {
				$rijschoolId = $this->user->getRijschoolId();
			}

			$result = $this->wsclient->WS_Rijlesplanner_GetAds(array (
			'RijschoolId' => $rijschoolId,
			'Position' => $position
			));
			$content = $result->Content;
			return stripslashes($content);
		} catch (SoapFault $e) {
			$this->logger->log("SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})", PEAR_LOG_INFO);
		}
	}
}
?>
